/*
 * Copyright 2008 Andrej Herich
 * 
 * http://azetclient.yw.sk/
 * http://azetclient.googlecode.com/
 * 
 * This file is part of AzetClient.
 * 
 * AzetClient is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * AzetClient is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with AzetClient.  If not, see <http://www.gnu.org/licenses/>.
 */

package sk.yw.azetclient.azet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import sk.yw.azetclient.Main;
import sk.yw.azetclient.connection.AbstractParser;
import sk.yw.azetclient.connection.PagesSaver;

/**
 *
 * @author error216
 */
public class MessageSender extends AbstractParser<Boolean> {
    
    private static final String TRUE_KEYWORD = "Vaša správa bola odoslaná";

    public Boolean parse(InputStream in) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in,
                Main.getProperty("azetclient.azet.encoding")));
        PagesSaver saver = new PagesSaver("send");
        
        boolean result = false;
        String line;
        while ((line = reader.readLine()) != null) {
            if (line.contains(TRUE_KEYWORD)) result = true;
            
            saver.println(line);
        }
        
        reader.close();
        saver.close();
        
        return result;
    }

}
